package com.yst.metho.web.application.projectversion.views;

import java.util.Collection;
import java.util.Iterator;

import nextapp.echo2.app.event.ChangeEvent;
import nextapp.echo2.app.event.ChangeListener;
import nextapp.echo2.app.list.AbstractListModel;
import nextapp.echo2.app.list.ListModel;

public class ProjectVersionListModel extends AbstractListModel implements ListModel, ChangeListener
{
	private Collection mProjectsList;

	/**
	 * @param projectsList
	 */
	public ProjectVersionListModel(Collection projectsList)
	{
		super();
		mProjectsList = projectsList;
	}

	public Object get(int index)
	{
		Object retour = null;
		Iterator it = mProjectsList.iterator();
		int i = -1;
		do
		{
			retour = it.next();
			i++;
		}
		while (i != index);
		return retour;
	}

	public int size()
	{
		return mProjectsList.size();
	}

	public void stateChanged(ChangeEvent e)
	{
		ProjectVersionTableModel model = (ProjectVersionTableModel) e.getSource();
		mProjectsList = model.getProjectVersionsList();
		fireIntervalAdded(0, mProjectsList.size() - 1);
	}

}
